import {computed, watch, ref, Ref} from 'vue';
import { useStore } from 'vuex';

export type CallbackType = (value: string) => void;
export const useFactory = () => {
  // 工厂变化事件
  const factoryChangeEvent = (callback: CallbackType): void => {
    const store = useStore();
    const currentFactory: Ref = ref(computed(() => store.getters['user/currentFactory']));
    watch(() => currentFactory.value, (value: any) => {
      if(callback){
        callback(value);
      }
    });
  }
  return {
    factoryChangeEvent,
  }
}